package com.ccq.service;

import com.alibaba.fastjson.JSON;
import com.ccq.mapper.UserMapper;
import com.ccq.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LastUserService {
    @Autowired
    UserMapper userMapper;

    public String userlist(Integer page){
        page=(page-1)*5;
        List<User> ls=userMapper.selectPage(page);
        String aListJson = JSON.toJSONString(ls);
        System.out.println(aListJson);
        return aListJson;
    }

    public String add(User user){
        int add=userMapper.insertSelective(user);
        List<User> ls=userMapper.selectPage(0);
        String aListJson = JSON.toJSONString(ls);
        return aListJson;
    }

    public String eidts(int id){
        User se=userMapper.selectByPrimaryKey(id);
        String aListJson = JSON.toJSONString(se);
        return aListJson;
    }

    public String edit(User user){
        int  se=userMapper.updateByPrimaryKey(user);
        List<User> ls=userMapper.selectPage(0);
        String aListJson = JSON.toJSONString(ls);
        return aListJson;
    }

    public String del(int id){
        int del=userMapper.deleteByPrimaryKey(id);
        List<User> ls=userMapper.selectPage(0);
        String aListJson = JSON.toJSONString(ls);
        System.out.println("删除成功！");
        return aListJson;
    }
}
